﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

class MoveState : Istate
{
    private enemy parent;
    public void enter(enemy parent)
    {
        Player.MyInstance.AddAttackers(parent);
        this.parent = parent;
    }

    public void exit()
    {
        parent.Xdir = 0;
        parent.Ydir = 0;


    }

    public void update()
    {

        if (parent.MyTrgt != null)
        {
            parent.Xdir = parent.MyTrgt.transform.position.x - parent.transform.position.x;
            parent.Ydir = parent.MyTrgt.transform.position.y - parent.transform.position.y;

            parent.transform.position = Vector2.MoveTowards(parent.transform.position, parent.MyTrgt.position, parent.MySpd * Time.deltaTime);
            float distance = Vector2.Distance(parent.transform.position, parent.MyTrgt.transform.position);
            if (distance <= parent.AtkRange)
            {
                parent.changeState(new AtkState());
            }
        }
        else
        {
            parent.changeState(new EvadeState());
        }
    }
}

